from bs4 import BeautifulSoup
import requests

url = "http://news.baidu.com/"
ua = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}

req = requests.get(url, headers=ua)
#print(req.content.decode('utf-8'))
html = req.content.decode('utf-8')
soup = BeautifulSoup(html, 'lxml')
#print("输入格式化的BeatifulSoup对象：", soup.prettify())

#print("获取head标签：", soup.head)

#print("获取title标签：", soup.title)

#print("获取第一个a标签：", soup.body.a)

#print("所以名称为a的标签：", soup.find_all('a'))

#print(type(soup.find_all('a')))

#print("所有名称为a的标签的个数：", len(soup.find_all('a')))

#print("soup的name:", soup.name)

#print("a的标签的name：", soup.a.name)

tag = soup.a
#print("tag的name:", tag.name)
print("tag的内容：", tag)

print("tag对象的全部属性：", tag.attrs)

print("href属性的值：", tag.attrs['href'])


